package com.hqyj.springBoot.modules.test.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.hqyj.springBoot.modules.common.entity.AbstractEntity;

import javax.persistence.*;
import java.util.List;

@Entity
@Table(name = "test_student")
public class Student extends AbstractEntity {

    private String name;
    private int age;

    //一对一的关系中,使用外键的一方,用targetEntity标注目标类模板(使用外键的一方,指向另一方)
    @OneToOne(targetEntity = Card.class,cascade = CascadeType.ALL,fetch = FetchType.EAGER)//cascade级联策略,fetch延迟加载
    //使用@JoinColumn,标注外键列名称
    @JoinColumn(name = "card_id",unique = true)
    private Card studentCard;

    //多对多中,不设中间表的一方,使用mappedBy进行关联
    @ManyToMany(mappedBy = "students",cascade = CascadeType.ALL,fetch = FetchType.EAGER)
    @JsonIgnore
    private List<Clazz> clazzes;


    public Card getCard() {
        return studentCard;
    }

    public void setCard(Card card) {
        this.studentCard = card;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public Card getStudentCard() {
        return studentCard;
    }

    public void setStudentCard(Card studentCard) {
        this.studentCard = studentCard;
    }

    public List<Clazz> getClazzes() {
        return clazzes;
    }

    public void setClazzes(List<Clazz> clazzes) {
        this.clazzes = clazzes;
    }
}
